using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace ObjectModel
{
    [Serializable]
    public class Customer : ItemBase 
    {
        #region fields
        string _companyName;
        string _contactName;
        string _contactTitle;
        string _address;
        string _city;
        string _region;
        string _postalCode;
        string _country;
        string _phone;
        string _fax;
        IList nativeOrders;
        OrderCollection _orders;
        bool ordersInitialised;
        #endregion

        #region ctor
        protected internal Customer() : base() { }
        #endregion

        #region properties
        public virtual string CompanyName
        {
            get { return _companyName;}
            set { _companyName = value; }
        }
        public virtual string ContactName
        {
            get { return _contactName; }
            set { _contactName = value; }
        }
        public virtual string ContactTitle
        {
            get { return _contactTitle; }
            set { _contactTitle = value; }
        }
        public virtual string Address
        {
            get { return _address; }
            set { _address = value; }
        }
        public virtual string City
        {
            get { return _city; }
            set { _city = value; }
        }
        public virtual string Region
        {
            get { return _region; }
            set { _region = value; }
        }
        public virtual string PostalCode
        {
            get { return _postalCode; }
            set { _postalCode = value; }
        }
        public virtual string Country
        {
            get { return _country; }
            set { _country = value; }
        }
        public virtual string Phone
        {
            get { return _phone; }
            set { _phone = value; }
        }
        public virtual string Fax
        {
            get { return _fax; }
            set { _fax = value; }
        }
        public virtual OrderCollection Orders
        {
            get
            {
                if (!ordersInitialised)
                {
                    IList nativeCollection = orders;

                    _orders = LazyLoadCollection<OrderCollection>(typeof(Customer), this, _orders, ref nativeCollection);

                    ordersInitialised = true;

                    orders = nativeCollection;

                    if (_orders == null)
                        _orders = new OrderCollection(orders);

                }
                return _orders;
            }
        }
        #endregion

        #region protected members
        protected virtual IList orders
        {
            get
            {
                if (nativeOrders == null)
                    nativeOrders = new ArrayList();

                return nativeOrders;
            }
            set
            {
                if (value != nativeOrders)
                    nativeOrders = value;
            }
        }
        #endregion
    }
}
